package cn.lili.modules.operationcenter.entity.vos;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.security.enums.SceneEnums;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * 运营中心搜索参数
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class OperationCenterSearchParams implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "运营中心id集合")
    private List<String> operationIds;

    @ApiModelProperty(value = "城市分站名称")
    private String operationName;

    @ApiModelProperty(value = "城市分站状态")
    private String status;

    @ApiModelProperty(value = "开始时间")
    private String startDate;

    @ApiModelProperty(value = "结束时间")
    private String endDate;

    @ApiModelProperty(value = "运营中心所属省份ID")
    private String provinceId;

    @ApiModelProperty(value = "场景", hidden = true)
    private String scene;

    @ApiModelProperty(value = "管理账号")
    private String username;

    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        if (CollUtil.isNotEmpty(operationIds)) {
            queryWrapper.in("loc.id", operationIds);
        }
        if (CharSequenceUtil.isNotEmpty(operationName)) {
            queryWrapper.like("loc.operation_name", operationName);
        }
        if (CharSequenceUtil.isNotEmpty(status)) {
            queryWrapper.eq("loc.status", status);
        }
        //按时间查询
        if (CharSequenceUtil.isNotEmpty(startDate)) {
            queryWrapper.ge("loc.create_time", DateUtil.parse(startDate));
        }
        if (CharSequenceUtil.isNotEmpty(endDate)) {
            queryWrapper.le("loc.create_time", DateUtil.parse(endDate));
        }
        if (CharSequenceUtil.isNotEmpty(provinceId)) {
            queryWrapper.eq("loc.province_id", provinceId);
        }
        if (CharSequenceUtil.isNotEmpty(scene)) {
            queryWrapper.eq("loc.scene", SceneEnums.getScene(scene).name());
        }
        if (CharSequenceUtil.isNotEmpty(username)) {
            queryWrapper.like("lu.username", username);
        }
        queryWrapper.eq("loc.delete_flag", false);
        queryWrapper.orderByDesc("loc.create_time");
        return queryWrapper;
    }
}
